package com.gitee.wsl.android.net

open class BaseRequest {
    //请求消息类型
    var requestMsgType = 0

    //期待接收的消息类型
    var responseMsgType = 0

    //发送数据
    lateinit var data: ByteArray

    //回调接口
    var callback: ResponseCallback? = null

    //起始时间
    private var startTime: Long = 0

    //超时门限
    private var threshold: Long = 0

    //期待接受数目
    var wantNumb = 1

    //已接收数目
    private var nowNumb = 0

    //是否发送出去
    var isSendOut = true
    fun setStartTime(startTime: Long) {
        this.startTime = startTime
    }

    fun setThreshold(threshold: Long) {
        this.threshold = threshold
    }

    fun addNowNumb() {
        nowNumb++
    }

    fun isTimeout(nowTime: Long): Boolean {
        val threshold = nowTime - startTime
        return threshold > this.threshold
    }

    val isReachWant: Boolean
        get() = nowNumb >= wantNumb
    val isWantInfinite: Boolean
        get() = wantNumb < 0

    //将需要发送的数据转成字节数组，需要子类重写
    protected val byteData: ByteArray = ByteArray(0)

}